libxl: IDL: refactor code to massage a type into a function argument
authorIan Campbell <ian.campbell@citrix.com>
Thu, 14 Jul 2011 12:22:36 +0000 (13:22 +0100)
committerIan Campbell <ian.campbell@citrix.com>
Thu, 14 Jul 2011 12:22:36 +0000 (13:22 +0100)
Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Committed-by: Ian Jackson <ian.jackson.citrix.com>
tools/libxl/gentypes.py
tools/libxl/libxltypes.py

index 6d798738f226327b3a61587a89d7c063a91d0d06..4d108f842133afb2ea189af1b1d5afd7284be81b 100644 (file)
@@ -84,11 +84,6 @@ def libxl_C_type_destroy(ty, v, indent = "    ", parent = None):
     else:
         deref = v + "."
         
-    if ty.passby == libxltypes.PASS_BY_REFERENCE and parent is not None:
-        makeref = "&"
-    else:
-        makeref = ""
-
     s = ""
     if isinstance(ty, libxltypes.KeyedUnion):
         if parent is None:
@@ -107,7 +102,7 @@ def libxl_C_type_destroy(ty, v, indent = "    ", parent = None):
                 s += libxl_C_type_destroy(f.type, deref + f.name, "", deref)
     else:
         if ty.destructor_fn is not None:
-            s += "%s(%s);\n" % (ty.destructor_fn, makeref + v)
+            s += "%s(%s);\n" % (ty.destructor_fn, ty.pass_arg(v, parent is None))
             
     if s != "":
         s = indent + s
index 29336d4a55f2b1bcf8aa2733eec56d189e940aa7..25430e262d37e97a2dece30416453a6a675d17a8 100644 (file)
@@ -50,6 +50,21 @@ class Type(object):
         else:
             return "%s %s" % (self.typename, n)
         
+    def pass_arg(self, n, isref=None, passby=None):
+        if passby is None: passby = self.passby
+        if isref is None: isref = self.passby == PASS_BY_REFERENCE
+
+        if passby == PASS_BY_REFERENCE:
+            if isref:
+                return "%s" % (n)
+            else:
+                return "&%s" % (n)
+        else:
+            if isref:
+                return "*%s" % (n)
+            else:
+                return "%s" % (n)
+
 class Builtin(Type):
     """Builtin type"""
     def __init__(self, typename, **kwargs):